import { onMounted, onUnmounted, ref } from 'vue'

export function useMouse(){
    const x=ref(0)
    const y=ref(0)

    function update(event){
        x.value=event.pageX
        y.value=event.pageY
    }

    // 执行在生命周期上
    onMounted(()=>window.addEventListener('mousemove',update))

    // 卸载副作用
    onUnmounted(()=>window.removeEventListener('mousemove',update))

    
    return{
        x,y
    }
}